﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using System.IO;
using Common;

public partial class website_admin_knowlegebase_otherslist : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;
        PageBegin();

        switch (RequestBase.GetFormString("otype"))
        {
            case "loadingdata":
                LoadingData();
                break;
            case "delete":
                Delete();
                break;
        }

        if (!IsPostBack)
        {
            txtCategoryNumber.Value = RequestBase.GetQueryString("c_number");
        }
    }
     
    #region 信息绑定
    void LoadingData()
    {
        string ctrl = "~/website_admin/knowlegebase/_controls/ctlKbArticleList.ascx";

        string SQL = " AND DeletionStateCode = 0";
        
        if (RequestBase.GetFormString("cnumber") != "")
        {
            SQL += " AND CategoryNumber LIKE '" + RequestBase.GetFormString("cnumber") + "%'";
        }
        else
        {
            SQL += " AND 1 <> 1";
        }

        Control uc_rep = LoadControl(ctrl);

        Repeater rptArticleList = (Repeater)uc_rep.FindControl("rptArticleList");

        DBUtility.Pagination pagination = new DBUtility.Pagination();
        try
        {
            if (!string.IsNullOrEmpty(RequestBase.GetString("index")))
                pagination.Sequence = Convert.ToInt32(RequestBase.GetString("index"));
            else
                pagination.Sequence = 1;

            pagination.ItemUnit = "条记录";
            pagination.SortSentence = " ORDER BY ArticleNumber ASC";
            pagination.Primarykey = "ArticleId";
            pagination.SearchField = "*";
            pagination.TableName = "vw_KbArticleBaseForList";
            if (!string.IsNullOrEmpty(RequestBase.GetString("pagesize")))
                pagination.PageSize = Convert.ToInt32(RequestBase.GetString("pagesize"));
            else
                pagination.PageSize = 20;
            pagination.UrlStr = "";
            pagination.ImagesPath = "../_imgs/grid/";
            pagination.SearchSentence = SQL.Trim();

            rptArticleList.DataSource = pagination.GetDataTable();
            rptArticleList.DataBind();

            pagination.PageBarFlexigrid();
            uc_rep.GetType().GetProperty("PaginationBar").SetValue(uc_rep, pagination.PageBar, null);

            StringBuilder strb = new StringBuilder();
            StringWriter sw = new StringWriter(strb);
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            rptArticleList.RenderControl(htw);

            BLL.AjaxHelper.ResponseWrite(strb.ToString());
        }
        catch (System.Threading.ThreadAbortException err)
        {
            //nothing   to   do   
        }
        catch (Exception err)
        {
            BLL.AjaxHelper.ResponseWrite(err.Message);
        }
    }
    #endregion

    #region 删除
    /// <summary>
    /// 删除目录
    /// </summary>
    void Delete()
    {
        /// 逻辑删除商品记录
        BLL.KbArticleBase.Delete(
            RequestBase.GetFormString("objectId") 
            );

        BLL.AjaxHelper.ResponseWrite("succeeded");
    }
    #endregion
}
